﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace FriendlyFire
{
    public class Helper
    {
        // vars
        Color currentGradientColor = Color.DarkGray;
        DBHelper dbh;

        public DBHelper DBHelper
        {
            get { return dbh; }
        }

        /// <summary>
        /// Constructor. Loads theme values from DB
        /// </summary>
        public Helper()
        {
            dbh = new DBHelper();   // Keep this instance here so we can use it everywhere.
            /*
             * We need to load the theme values on startup. The database
             * cannot handle the ammount of conncurrent calls that would 
             * result otherwise.
             */
            CurrentGradientColor = Color.FromName(dbh.GetConfig("bggradientcolor"));
        }

        public Color CurrentGradientColor
        {
            get { return currentGradientColor; }
            set { currentGradientColor = value; }
        }

        public void DrawDefaultBackGroundGradient(Graphics g, Rectangle cr)
        {
            LinearGradientBrush gb = new LinearGradientBrush(new Point(0, 0),
                                                                    new Point(0, cr.Height),
                                                                    Color.White,
                                                                    CurrentGradientColor);
            if (cr.Height > 0 && cr.Width > 0)
            {
                g.FillRectangle(gb, cr);
            }
        }
    }
}
